// Reflect 可以调用原对象的方法
var obj = {};
var loggedObj = new Proxy(obj, {
    get(target, name) {
        console.log('get', target, name);
        return Reflect.get(target, name);
    },
    deleteProperty(target, name) {
        console.log('delete ' + name);
        return Reflect.deleteProperty(target, name);
    },
    has(target, name) {
        console.log('has ' + name);
        return Reflect.has(target, name);
    },
    set: function(target, name, value, receiver) {
        var success = Reflect.set(target,name, value, receiver);
        if (success) {
            console.log('property ' + name + ' on ' + target + ' set to ' + value);
        }
        return success;
    }
});

loggedObj.name="YangMi";
loggedObj.name;
'name' in loggedObj;  //触发 has(target, name)
delete loggedObj['name']; //触发 deleteProperty(target, name)



var myObject = {
    foo: 1,
    bar: 2,
    get baz() {
        return this.foo + this.bar;
    },
    set zoo(value) {
        return this.foo = value;
    }
};

console.log(Reflect.get(myObject, 'foo')); // 1
console.log(Reflect.get(myObject, 'bar')); // 2
console.log(Reflect.get(myObject, 'baz')); // 3

Reflect.set(myObject, 'foo', 2);
console.log(myObject.foo); // 2

Reflect.set(myObject, 'zoo', 3);
console.log(myObject.foo); // 3